package com.eusoft.grades.school;
/**
 * @author Nick Eubanks
 * 
 * ALTERED FOR COMPATIBILITY
 *
 * Copyright (C) 2010 Android Infinity (http://www.androidinfinity.com)
 *
 */
import java.io.Serializable;
import java.util.ArrayList;

//import com.eusoft.grades.util.Storage;

/**
 * 
 * @author Nick Eubanks
 */
public class Semester implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 7996374032307966541L;
	public ArrayList<Course> courses = new ArrayList<Course>();
	public String notes = "", ID = "";
	/*
	 * Term: 0: Spring 1: Summer 2: Fall 3: Winter
	 */
	public int term = 0;

	public int year = 00; // 20+year = year

	public double calculateSemesterGPA() {
		double gpa = 0;
		if (courses != null) {

			double gpoints = 0;
			double hours = 0;

			Student s = new Student();//Storage.loadStudent();
			for (Course cour : courses) {
				if (cour.isGraded) {
					String letter = cour.calcLetterGrade();
					if (letter.equals("F")) {
						hours += cour.hours;
					} else {
						for (Letter l : s.overallScale.scale) {
							if (l.identifier.equals(letter)) { // found the
																// grade
								gpoints += l.gradePoints * cour.hours;
								hours += cour.hours;

							}
						}
					}

				}

			}
			if (hours != 0)
				gpa = gpoints / hours;
			gpoints = 0;
			hours = 0;
		}

		return gpa;
	}

	public double calculateSemesterHours() {
		double hours = 0;
		if (courses != null) {

			for (Course cour : courses) {
				if (cour.isGraded) {
					hours += cour.hours;
				}
			}

		}

		return hours;
	}
	
	public double calculateTotalSemesterHours(){
		double hours = 0;
		if (courses != null) {

			for (Course cour : courses) {
					hours += cour.hours;
			}

		}

		return hours;
	}

	@Override
	public String toString() {
		String semStr = "";
		if (term == 0)
			semStr = "Spring ";
		if (term == 1)
			semStr = "Summer ";
		if (term == 2)
			semStr = "Fall   ";
		if (term == 3)
			semStr = "Winter ";
                String yearStr = ""+year;
                if(yearStr.length() == 1) yearStr = "0" + yearStr;
                yearStr = "20" + yearStr;
		return semStr + yearStr;
	}

}
